package com.ycg.biquge.aop;

import cn.hutool.core.util.StrUtil;
import com.ycg.biquge.exception.TypeNotMatchException;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @author YCG
 * @date 2024-05-16 16:18
 * @description 检查小说分类
 */
@Aspect
@Component
public class CheckTypeAOP {

    @Pointcut("@annotation(com.ycg.biquge.uitls.CheckType)")
    public void checkType(){};

    /**
     * 小说类型
     */
    private final String[] types = {"玄幻奇幻", "武侠仙侠", "都市言情", "历史军事", "网游竞技", "科幻灵异", "女生频道"};


    @After(value = "checkType()")
    public void check(JoinPoint jp){
        Object[] args = jp.getArgs();
        String type = (String) args[0];
        if (Arrays.stream(types).noneMatch(item -> StrUtil.equals(type,item))) {
            throw new TypeNotMatchException("小说类型不匹配");
        }

    }
}
